﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using PowerCreator.LMS.Common.Script;
using PowerCreator.LMS.Task.Entity;
using PowerCreator.LMS.Web.Task;
using System.Collections.Generic;

public partial class sysadmin_TaskManager_TaskGroupManager : PowerCreator.LMS.Web.Base.BasePage
{
    TaskGroupManag objTaskGroupManag = new TaskGroupManag();
    TaskGroupInfoManag objTaskGroupInfoManag = new TaskGroupInfoManag();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            string search = GetSearch();
            BinderPager(search);
            BinderGV(search, 1);
            InitPage();
        }
    }

    protected override void InitPage()
    {
        lbl_InfoTitle.Text = "任务分组管理";//GetLanageValueByKey("lab_ManagerPaperInfo_InfoTitle", PowerCreator.LMS.Language.LanagetItemType.Page);

        base.InitPage();
    }

    private string GetSearch()
    {
        string search = " FKTaskGpCreateID=" + GetLoginEntity.UserID.ToString();
        return search.ToString();
    }
    private void BinderPager(string search)
    {
        AspNetPager1.RecordCount = objTaskGroupManag.Count(search);
        AspNetPager1.PageSize = LMSPageSize;

    }

    private void BinderGV(string search, int pageIndex)
    {

        DataTable dt = new DataTable();
        dt = objTaskGroupManag.Query(search, "", LMSPageSize, pageIndex);



        //gvConfigure.Columns[5].HeaderText = GetLanageValueByKey("btn_ManagerQuestion_Work", PowerCreator.LMS.Language.LanagetItemType.Page);

        gvConfigure.DataKeyNames = new string[] { "TaskGpID" };
        gvConfigure.DataSource = dt;
        gvConfigure.DataBind();





        PreAspNetPager(AspNetPager1);

    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderGV(search, AspNetPager1.CurrentPageIndex);
    }

    protected void gvConfigure_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string TaskGpName = ((TextBox)(gvConfigure.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim();
        
        int TaskGpID = int.Parse(gvConfigure.DataKeys[e.RowIndex].Value.ToString());

        TaskGroup objTaskGroup = objTaskGroupManag.Load(TaskGpID);
        objTaskGroup.TaskGpName = TaskGpName;

        objTaskGroupManag.Update(objTaskGroup);

        gvConfigure.EditIndex = -1;

        string search = GetSearch();
        BinderPager(search);
        BinderGV(search, 1);
    }
    protected void gvConfigure_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        gvConfigure.EditIndex = -1;
        string search = GetSearch();
        BinderPager(search);
        BinderGV(search, 1);
    }
    protected void gvConfigure_RowEditing(object sender, GridViewEditEventArgs e)
    {
        gvConfigure.EditIndex = e.NewEditIndex;
        string search = GetSearch();
        BinderPager(search);
        BinderGV(search, 1);
    }
    protected void gvConfigure_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int TaskGpID = int.Parse(gvConfigure.DataKeys[e.RowIndex].Value.ToString());

        string searchTaskGroupInfo = " FKTaskGpID =" + TaskGpID.ToString();
        DataTable dtTaskGroupInfo = objTaskGroupInfoManag.Query(searchTaskGroupInfo);

        for (int i = 0; i < dtTaskGroupInfo.Rows.Count; i++)
        {
            int TaskGIfID = int.Parse(dtTaskGroupInfo.Rows[i]["TaskGIfID"].ToString());

            objTaskGroupInfoManag.Remove(TaskGIfID);
        }

        objTaskGroupManag.Remove(TaskGpID);

        string search = GetSearch();
        BinderPager(search);
        BinderGV(search, 1);
    }
    protected void btnAddNew_Click(object sender, EventArgs e)
    {
        Script.RedirectURL("AddTaskGroup.aspx");
    }
    protected void gvConfigure_RowCreated(object sender, GridViewRowEventArgs e)
    {
        //gvConfigure.EditIndex = e.NewEditIndex;
        
        //string TaskGpName = ((TextBox)(e.Row.Cells[1].Controls[0])).Text.ToString().Trim();
 

        //string TaskGpRemark = "";

        //DateTime TaskGpCreateTime = DateTime.Now;
        //int FKTaskGpCreateID = 10001;// GetLoginEntity.UserID;

        //TaskGroup model = new TaskGroup();

        //model.TaskGpName = TaskGpName;
        //model.TaskGpRemark = TaskGpRemark;
        //model.TaskGpCreateTime = TaskGpCreateTime;
        //model.FKTaskGpCreateID = FKTaskGpCreateID;


        //bool result;
        //result = objTaskGroupManag.AddNew(model);
    }
}
